
package com.bj58.mis.apm.wf.controllers;

import com.bj58.biz.wfutility.actionresult.JsonActionResult;
import com.bj58.biz.wfutility.actionresult.vo.JsonVo;
import com.bj58.data.roc.service.project.CubeBaseService;
import com.bj58.data.roc.service.project.ProjectService;
import com.bj58.data.roc.service.project.model.CubeBase;
import com.bj58.data.roc.service.project.model.Project;
import com.bj58.pay.core.utils.PageList;
import com.bj58.spat.scf.client.SCFInit;
import com.bj58.spat.scf.client.proxy.builder.ProxyFactory;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.Path;

/**
 * 〈一句话功能简述〉<br> 
 * 〈scf测试类〉
 *
 * @author zhangyu84
 * @create 2018/7/4
 * @since 1.0.0
 */
public class ScfController extends MvcController {
    private CubeBaseService cubeBaseService;
    private ProjectService projectService;
    private  ScfController() {
        //调用SCF服务
        //1.准备本地scf.conf配置文件路径
        //String scfconf = System.getProperty("user.dir")+"\\src\\main\\resources\\scf.config";
        String scfconf =ScfController.class.getClassLoader().getResource("").getPath()+ "scf.config";
        System.out.println(scfconf);
        //2.scf服务初始化
        SCFInit.init(scfconf);
        //3.准备SCF服务访问地址
        String cubeUrl = "tcp://rocserver/cubeBaseService";
        String projectUrl = "tcp://rocserver/projectService";
        //4.调用SCF服务
        cubeBaseService = ProxyFactory.create(CubeBaseService.class, cubeUrl);
        projectService = ProxyFactory.create(ProjectService.class, projectUrl);
    }
    @GET
    @Path("cubeBase")
    public JsonActionResult cubeBase() {
        JsonVo jsonVo = new JsonVo("");
        jsonVo.setCode(0);
        jsonVo.setMsg("false");
        CubeBase cubeBase = new CubeBase();
        try {
            PageList<CubeBase> cubeBasePageList = cubeBaseService.getPageList(cubeBase, 1, 10, null, true, null);
            jsonVo.setData(cubeBasePageList);
            jsonVo.setMsg("success");
            jsonVo.setCode(1);
            return new JsonActionResult(jsonVo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new JsonActionResult(jsonVo);
    }
    @GET
    @Path("project")
    public JsonActionResult project() {
        JsonVo jsonVo = new JsonVo("");
        jsonVo.setCode(0);
        jsonVo.setMsg("false");
        try {
            PageList<Project> projectPageList = projectService.getPageList(new Project(),1,10,null,true,null);
            jsonVo.setData(projectPageList);
            jsonVo.setMsg("success");
            jsonVo.setCode(1);
            return new JsonActionResult(jsonVo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new JsonActionResult(jsonVo);
    }

}
